package com.heima.schedule.controller;

import com.heima.common.redis.RedisCacheService;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/task")
public class ScheduleClient {
    @Autowired
    private TaskService taskService;
    @Autowired
    private RedisCacheService redisCacheService;
    /**
     * 添加任务
     * @param task   任务对象
     *
     */
    @PostMapping("/add")
    public void addTask(@RequestBody Task task){
        taskService.addTask(task);
    }

    /**
     * 取消任务
     * @param taskId        任务id
     * @return              取消结果
     */
    @GetMapping("/cancel/{taskId}")
    public ResponseResult cancelTask(@PathVariable("taskId") long taskId) {

        return null;
    }

    /**
     * 按照类型和优先级来拉取任务
     * @param type
     * @param priority
     */
    @GetMapping("/poll/{type}/{priority}")
    public Task poll(@PathVariable("type") int type,@PathVariable("priority")  int priority) {
        Task poll = taskService.poll(type, priority);
        return poll;
    }
}
